﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("SCS");

SCS.DialogBehavior = function (element) {
    SCS.DialogBehavior.initializeBase(this, [element]);

    /* Fields
    ****************************************************************************************************************/

};

SCS.DialogBehavior.prototype = {

    /* Setup
    ****************************************************************************************************************/

    initialize: function () {

        SCS.DialogBehavior.callBaseMethod(this, 'initialize');
    },

    /* Teardown
    ****************************************************************************************************************/

    dispose: function () {

        SCS.DialogBehavior.callBaseMethod(this, 'dispose');
    },

    /* Private and Protected Methods
    ****************************************************************************************************************/

    // overrides base class method
    _layout: function () {

        var e = new Sys.CancelEventArgs();

        this.raiseRepositioning(e);

        if (!e.get_cancel()) {

            //alert("Repositioning");
            SCS.DialogBehavior.callBaseMethod(this, '_layout');
        }
    },

    _onOk: function (e) {

        var args = new SCS.DialogButtonClickEventArgs('OK');

        this.raiseButtonClicked(args);

        SCS.DialogBehavior.callBaseMethod(this, '_onOk', [e]);
    },

    _onCancel: function (e) {

        var args = new SCS.DialogButtonClickEventArgs('Cancel');

        this.raiseButtonClicked(args);

        SCS.DialogBehavior.callBaseMethod(this, '_onCancel', [e]);
    },

    /* Events
    ****************************************************************************************************************/

    add_Repositioning: function (handler) {

        this.get_events().addHandler('Repositioning', handler);
    },
    remove_Repositioning: function (handler) {

        this.get_events().removeHandler('Repositioning', handler);
    },
    raiseRepositioning: function (eventArgs) {

        var handler = this.get_events().getHandler('Repositioning');
        if (handler)
            handler(this, eventArgs);
    },

    add_ButtonClicked: function (handler) {

        this.get_events().addHandler('ButtonClicked', handler);
    },
    remove_ButtonClicked: function (handler) {

        this.get_events().removeHandler('ButtonClicked', handler);
    },
    raiseButtonClicked: function (eventArgs) {

        var handler = this.get_events().getHandler('ButtonClicked');
        if (handler)
            handler(this, eventArgs);
    }
};

/* Registration
****************************************************************************************************************/

SCS.DialogBehavior.registerClass('SCS.DialogBehavior', Sys.Extended.UI.ModalPopupBehavior);

SCS.DialogButtonClickEventArgs = function (name) {

    SCS.DialogButtonClickEventArgs.initializeBase(this);

    this._name = name;
};

SCS.DialogButtonClickEventArgs.prototype = {
    
    get_Name: function () {
        return this._name;
    },
    set_Name: function (value) {
        this._names = value;
    }
};

SCS.DialogButtonClickEventArgs.registerClass('SCS.DialogButtonClickEventArgs', Sys.CancelEventArgs);